package com.sky.pay.component;

import com.sky.pay.service.OrderService;
import com.sky.pay.service.RefundService;
import com.sky.pay.service.WeixinPayService;
import com.sky.pay.vo.Order;
import com.sky.pay.vo.Refund;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author yangsk
 */

@Component
public class WeixinPayTask {

    @Autowired
    private OrderService orderService;

    @Autowired
    private WeixinPayService weixinPayService;

    @Autowired
    private RefundService refundService;

    /**
     * 没30秒执行一次，查询查过5分钟未支付的订单
     */
    @Scheduled(cron = "0/30 * * * * ?")
    public void weixinPayOrderConfirm() throws Exception {
        //暂定超过5分钟，未支付的订单
       List<Order> list =  orderService.getNoPayOrderByDuration(5);
       //调用微信查询订单接口，查看交易订单状态
       for(Order order:list){
           weixinPayService.checkWeixinPayOrderStatus(order.getOrderNo());
       }
    }

    @Scheduled(cron = "0/30 * * * * ?")
    public void weixinRefundOrderConfirm() throws Exception {
        List<Refund> list =  refundService.getNoRefundOrderByDuration(5);
        //调用微信查询订单接口，查看交易订单状态
        for(Refund refund:list){
            weixinPayService.checkWeixinRefundOrderStatus(refund.getRefundNo());
        }
    }

}
